<?php 
include_once($_SERVER["DOCUMENT_ROOT"]."/bolsa_trabajo/util/database.php");

class CargosDTO
{

	public function __construct() {
		exit('Init function is not allowed');
	}

	public static function getNombreCargos($idCargos){
		$con = Database::connect();
		$query = "select * from  tbl_cargo where id_cargo = ?";
	
		$stmt = $con->prepare( $query );
	
		$stmt->bindParam(1, $id_cargo);
		$stmt->execute();
		
		Database::disconnect();
		
		$num = $stmt->rowCount();
		
		$res = null;
		if($num>0){
			while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
			extract($row);
			$res = $descripcion;
			}
		}
		
	
		return $res;
	}
	
	
	public static function getCargos($descripcion){
		$con = Database::connect();
		$query = "select * from  tbl_cargo where descripcion like '%$descripcion%'";
		
		$stmt = $con->prepare( $query );

		//$stmt->bindParam(1, $descripcion);
		$stmt->execute();
		Database::disconnect();
		return $stmt;


	}
	
	public static function getCargosById($idCargos){
		$con = Database::connect();
		$query = "select * from  tbl_cargo where id_cargo = ?";
	
		$stmt = $con->prepare( $query );
	
		$stmt->bindParam(1, $idCargos);
		$stmt->execute();
		Database::disconnect();
		return $stmt;
	
	
	}
	public static function delete($id_cargo){
		$con = Database::connect();
		$query = "delete from  tbl_cargo where id_cargo = ?";
	
		$stmt = $con->prepare( $query );
	
		$stmt->bindParam(1, $id_cargo);
		
		if($stmt->execute()){
			return true;
		}else{
			error_log('Fallo borrar cargo',0);
			return false;
		}
	}	
	
	public static function insert($descripcionCargo){
		$con = Database::connect();
		$query = "insert into tbl_cargo set descripcion = ?";
		
		$stmt = $con->prepare( $query );
		$stmt->bindParam(1, $descripcionCargo);
		if($stmt->execute()){
			return true;
		}else{
			error_log('Fallo Insert de Cargo: ' . $descripcionCargo,0);
			return false;
		}
	}
	
	public static function update($descripcion, $id_cargo){
		$con = Database::connect();
		$query = "update tbl_cargo SET descripcion = ? where id_cargo = ?";
		
	
		$stmt = $con->prepare( $query );
	
		$stmt->bindParam(1, $descripcion);
		$stmt->bindParam(2, $id_cargo);
		$stmt->execute();
		
		if($stmt->execute()){
			return true;
		}else{
			error_log('Fallo Update de Cargo',0);
			return false;
		}
	}
	
	
	



	}

?>